home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DIAGTOOL / MEMSZ240.ZIP;1 / CONFIG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-23  |  10.5 KB  |  250 lines

  1. /***************************************************************** CONFIG.CPP
  2.  *                                                                          *
  3.  *                        Clock Configuration Dialog                        *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #define INCL_WINSTDSPIN
  10. #include <os2.h>
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "debug.h"
  16. #include "support.h"
  17.  
  18. #include "memsize.h"
  19. #include "config.h"
  20.  
  21.  
  22. /****************************************************************************
  23.  *                                                                          *
  24.  *                     Definitions & Declarations                           *
  25.  *                                                                          *
  26.  ****************************************************************************/
  27.  
  28.   // Function Prototypes
  29.  
  30. static METHODFUNCTION InitDlg ;
  31. static METHODFUNCTION Command ;
  32. static METHODFUNCTION OK ;
  33. static METHODFUNCTION Cancel ;
  34.  
  35.  
  36. /****************************************************************************
  37.  *                                                                          *
  38.  *      "Configure" Dialog Processor                                            *
  39.  *                                                                          *
  40.  ****************************************************************************/
  41.  
  42. extern MRESULT EXPENTRY ConfigureProcessor ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  43.  
  44.  /***************************************************************************
  45.   * Dispatch the message according to the method table and return the       *
  46.   *   result.  Any messages not defined above get handled by the system     *
  47.   *   default dialog processor.                                             *
  48.   ***************************************************************************/
  49.  
  50.   static METHOD Methods [] = {
  51.     { WM_INITDLG, InitDlg },
  52.     { WM_COMMAND, Command }
  53.   } ;
  54.  
  55.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  56. }
  57.  
  58. /****************************************************************************
  59.  *                                                                          *
  60.  *      Initialize Dialog                                                   *
  61.  *                                                                          *
  62.  ****************************************************************************/
  63.  
  64. static MRESULT APIENTRY InitDlg ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  65.  
  66.  /***************************************************************************
  67.   * Get initial parameters.                                                 *
  68.   ***************************************************************************/
  69.  
  70.   PCONFIG_PARMS Parms = (PCONFIG_PARMS) ( PVOIDFROMMP ( mp2 ) ) ;
  71.  
  72.   WinSetWindowPtr ( hwnd, QWL_USER, Parms ) ;
  73.  
  74.  /***************************************************************************
  75.   * Associate the help instance.                                            *
  76.   ***************************************************************************/
  77.  
  78.   WinSetWindowUShort ( hwnd, QWS_ID, Parms->id ) ;
  79.  
  80.   if ( Parms->hwndHelp ) {
  81.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  82.   }
  83.  
  84.  /***************************************************************************
  85.   * Load the list box.                                                      *
  86.   ***************************************************************************/
  87.  
  88.   for ( int i=0; i<Parms->ItemCount; i++ ) {
  89.     WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_INSERTITEM,
  90.       MPFROMSHORT(LIT_END), MPFROMP(Parms->ItemNames[i]) ) ;
  91.  
  92.     if ( Parms->ItemFlags[i] ) {
  93.       WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_SELECTITEM,
  94.         MPFROMSHORT(SHORT(i)), MPFROMSHORT(TRUE) ) ;
  95.     }
  96.   }
  97.  
  98.  /***************************************************************************
  99.   * Set the radio button and checkbox values.                               *
  100.   ***************************************************************************/
  101.  
  102.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_HIDECONTROLS,
  103.     BM_SETCHECK, MPFROMSHORT(Parms->HideControls), 0 ) ;
  104.  
  105.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_FLOAT,
  106.     BM_SETCHECK, MPFROMSHORT(Parms->Float), 0 ) ;
  107.  
  108.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ANIMATE,
  109.     BM_SETCHECK, MPFROMSHORT(Parms->Animate), 0 ) ;
  110.  
  111.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_FSNAME,
  112.     BM_SETCHECK, MPFROMSHORT(Parms->ShowFileSystemNames), 0 ) ;
  113.  
  114.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_DLABEL,
  115.     BM_SETCHECK, MPFROMSHORT(Parms->ShowDiskLabels), 0 ) ;
  116.  
  117.  /***************************************************************************
  118.   * Set the limits and initial value of the spin-button controls.           *
  119.   ***************************************************************************/
  120.  
  121.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_PRIORITY,
  122.     SPBM_SETLIMITS, (MPARAM)PRTYD_MAXIMUM, (MPARAM)0 ) ;
  123.  
  124.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_PRIORITY,
  125.     SPBM_SETCURRENTVALUE, (MPARAM)(Parms->MonitorPriority), NULL ) ;
  126.  
  127.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  128.     SPBM_SETLIMITS, (MPARAM)300L, (MPARAM)10L ) ;
  129.  
  130.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  131.     SPBM_SETCURRENTVALUE, (MPARAM)(Parms->TimerInterval/100), NULL ) ;
  132.  
  133.  /***************************************************************************
  134.   * Return without error.                                                   *
  135.   ***************************************************************************/
  136.  
  137.   return ( MRFROMSHORT ( FALSE ) ) ;
  138. }
  139.  
  140. /****************************************************************************
  141.  *                                                                          *
  142.  *      Process commands received by the Configure Dialog                       *
  143.  *                                                                          *
  144.  ****************************************************************************/
  145.  
  146. static MRESULT APIENTRY Command ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  147.  
  148.  /***************************************************************************
  149.   * Dispatch the message without a default message processor.               *
  150.   ***************************************************************************/
  151.  
  152.   static METHOD Methods [] = {
  153.     { DID_OK,     OK     },
  154.     { DID_CANCEL, Cancel },
  155.   } ;
  156.  
  157.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), PFNWP(NULL) ) ) ;
  158. }
  159.  
  160. /****************************************************************************
  161.  *                                                                          *
  162.  *      Process the Configure Dialog's OK button being pressed.             *
  163.  *                                                                          *
  164.  ****************************************************************************/
  165.  
  166. static MRESULT APIENTRY OK ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  167.  
  168.  /***************************************************************************
  169.   * Find the instance data.                                                 *
  170.   ***************************************************************************/
  171.  
  172.   PCONFIG_PARMS Parms = PCONFIG_PARMS ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  173.  
  174.  /***************************************************************************
  175.   * Query the list box items for their selection.                           *
  176.   ***************************************************************************/
  177.  
  178.   for ( int i=0; i<Parms->ItemCount; i++ ) {
  179.     Parms->ItemFlags[i] = FALSE ;
  180.   }
  181.  
  182.   SHORT Selection = LIT_FIRST ;
  183.   do {
  184.     Selection = BOOL ( SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  185.       IDD_CONFIG_ITEMS, LM_QUERYSELECTION,
  186.       MPFROMSHORT(SHORT(Selection)), 0 ) ) ) ;
  187.  
  188.     if ( Selection != LIT_NONE ) {
  189.       Parms->ItemFlags[Selection] = TRUE ;
  190.     }
  191.   }
  192.   while ( Selection != LIT_NONE ) ;
  193.  
  194.  /***************************************************************************
  195.   * Query the buttons for their new settings.                               *
  196.   ***************************************************************************/
  197.  
  198.   Parms->HideControls = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  199.     IDD_CONFIG_HIDECONTROLS, BM_QUERYCHECK, 0L, 0L ) ) ;
  200.  
  201.   Parms->Float = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  202.     IDD_CONFIG_FLOAT, BM_QUERYCHECK, 0L, 0L ) ) ;
  203.  
  204.   Parms->Animate = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  205.     IDD_CONFIG_ANIMATE, BM_QUERYCHECK, 0L, 0L ) ) ;
  206.  
  207.   Parms->ShowFileSystemNames = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  208.     IDD_CONFIG_FSNAME, BM_QUERYCHECK, 0L, 0L ) ) ;
  209.  
  210.   Parms->ShowDiskLabels = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  211.     IDD_CONFIG_DLABEL, BM_QUERYCHECK, 0L, 0L ) ) ;
  212.  
  213.  /***************************************************************************
  214.   * Query the spinbuttons for their new settings.                           *
  215.   ***************************************************************************/
  216.  
  217.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_PRIORITY, SPBM_QUERYVALUE,
  218.     &Parms->MonitorPriority, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  219.  
  220.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER, SPBM_QUERYVALUE,
  221.     &Parms->TimerInterval, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  222.  
  223.   Parms->TimerInterval *= 100 ;
  224.  
  225.  /***************************************************************************
  226.   * Dismiss the dialog with a TRUE status.                                  *
  227.   ***************************************************************************/
  228.  
  229.   WinDismissDlg ( hwnd, TRUE ) ;
  230.  
  231.   return ( 0 ) ;
  232. }
  233.  
  234. /****************************************************************************
  235.  *                                                                          *
  236.  *      Process the Configure Dialog's being cancelled.                     *
  237.  *                                                                          *
  238.  ****************************************************************************/
  239.  
  240. static MRESULT APIENTRY Cancel ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  241.  
  242.  /***************************************************************************
  243.   * Dismiss the dialog with a TRUE status.                                  *
  244.   ***************************************************************************/
  245.  
  246.   WinDismissDlg ( hwnd, FALSE ) ;
  247.  
  248.   return ( 0 ) ;
  249. }
  250.